package be.kuleuven.mume.framework;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.text.format.DateFormat;
import be.kuleuven.mume.listProxys.DeviderProxy.Devidable;

public class AgendaItem implements Devidable, Serializable,Comparable<AgendaItem>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5575743145261494439L;
	public static final String TYPE_ID = "TYPE";
	private static String url = Mobilenvi.getSingelton().BASEURL + "/api/agenda";
	private static String updatesUrl = url + "/updates";
	public static final String imageUrl = Mobilenvi.getSingelton().BASEURL + "/images/licons/ti_office_calendar.png";
	public static final String ADD_URL = url + "/add/afspraak";
	public static final String AGENDA_ID = "AGENDATYPE";
	private String id = "";
	private String vakName = "";
	private String vakId = "";
	private String locatie = "";
	private int minutes;
	private int hours;
	private Date datum;
	private Date timeStamp;
	private String type = "";
	private TypeItem typeItem = TypeItem.Undefined;
	private String omschrijving = "";
	private String met ="";
	private boolean isUpdate = false;
	
	public static enum TypeItem{Alles,Undefined,Deathline,Uurooster,Afspraken,VrijeTijd,Updates}
	public static Map<String, TypeItem> types;
	
	public AgendaItem(){
		if(types == null){
			types = new HashMap<String, TypeItem>();
			types.put("afspraak", TypeItem.Afspraken);
			types.put("deadline", TypeItem.Deathline);
			types.put("vrije_tijd",TypeItem.VrijeTijd);
			types.put("uurrooster", TypeItem.Uurooster);
		}
	}
	
	public String getDevider(Context context) {
		java.text.DateFormat df = DateFormat.getDateFormat(context);
		if(isUpdate)
			return df.format(timeStamp);
		return df.format(datum);
	}
	
	public int compareTo(AgendaItem another) {
		if(isUpdate)
			return -this.timeStamp.compareTo(another.getTimeStamp());
		return this.datum.compareTo(another.getDatum());
	}
	
	public void setAsUpdate(boolean f){
		this.isUpdate = f;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	public String getId() {
		return id;
	}
	public void setVakName(String vakName) {
		this.vakName = vakName;
	}
	public String getVakName() {
		return vakName;
	}
	public void setVakId(String vakId) {
		this.vakId = vakId;
	}
	public String getVakId() {
		return vakId;
	}
	public void setLocatie(String locatie) {
		this.locatie = locatie;
	}
	public String getLocatie() {
		return locatie;
	}
	public void setMinutes(Integer minutes) {
		this.minutes = minutes;
	}
	public int getMinutes() {
		return minutes;
	}
	public void setHours(Integer hours) {
		this.hours = hours;
	}
	public int getHours() {
		return hours;
	}
	public void setDatum(Date datum) {
		this.datum = datum;
	}
	public Date getDatum() {
		return datum;
	}
	public Date getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(Date timeStamp) {
		this.timeStamp = timeStamp;
	}

	public Date getEindDatum(){
		Calendar d = Calendar.getInstance();
		d.setTime(datum);
		d.add(Calendar.HOUR, hours);
		d.add(Calendar.MINUTE, minutes);
		return d.getTime();
	}
	public void setType(String type) {
		this.type = type;
		if(types.containsKey(type))
			this.typeItem = types.get(type);
	}
	public String getType() {
		return type;
	}
	public TypeItem getTypeItem(){
		return typeItem;
	}
	public void setOmschrijving(String omschrijving) {
		this.omschrijving = omschrijving;
	}
	public String getOmschrijving() {
		return omschrijving;
	}
	public String getMet() {
		return met;
	}

	public void setMet(String met) {
		this.met = met;
	}

	public static String getUrl(TypeItem t) {
		switch(t){
		case Alles :
			return url;
		case Deathline :
			return url + "?type=deadline";
		case Uurooster:
			return url+ "?type=uurrooster";
		case Afspraken:
			return url + "?type=afspraken";
		case VrijeTijd:
			return url + "?type=vrijetijd";
		case Updates:
			return updatesUrl;
		default :
			return url;
		}
	}
	public boolean isUpdate(){
		return isUpdate;
	}
}
